<template>
  <!--会签管理-线下物资招采询价弹窗-表单-->
  <a-spin :spinning="confirmLoading">
    <j-form-container class="scroll-view" style="height: 600px">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row style="margin-bottom: 20px;" v-if="pageType === 'add' || pageType === 'edit' || pageType === 'anew'">
          <a-col :span="24">
            <span style="font-size: 20px; font-weight: bold;">{{billsTemplateName}}</span>
          </a-col>
        </a-row>

        <template v-if="pageType === 'detail'">
          <a-row>
            <a-col :span="12">
              <a-form-model-item label="审批编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="approvNumber"
                style="margin-bottom: 10px;">
                <a-input :disabled="disabled" v-model="model.approvNumber" placeholder="请输入介绍"></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item label="提交时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="submitTime"
                style="margin-bottom: 10px;">
                <j-date v-model="model.submitTime" :showTime="true" :disabled="disabled" date-format="YYYY-MM-DD "
                  style="width: 100%" placeholder="请选择提交时间"></j-date>
              </a-form-model-item>
            </a-col>
          </a-row>

          <a-row>
            <a-col :span="12">
              <a-form-model-item label="发起人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userName"
                style="margin-bottom: 10px;">
                <a-input :disabled="disabled" v-model="model.userName" placeholder="请输入发起人"></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item label="职位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="post"
                style="margin-bottom: 10px;">
                <a-select :disabled="disabled" placeholder="请选择职位" v-model="model.post">
                </a-select>
              </a-form-model-item>
            </a-col>
          </a-row>

          <a-row>
            <a-col :span="12">
              <a-form-model-item label="申请部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="departId"
                style="margin-bottom: 10px;">
                <a-input :disabled="disabled" placeholder="请选择部门" v-model="model.departName">
                </a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="status"
                style="margin-bottom: 10px;">
                <a-select :disabled="disabled" placeholder="请选择状态" v-model="model.status">
                  <a-select-option value="0">未提交</a-select-option>
                  <a-select-option value="1">审核中</a-select-option>
                  <a-select-option value="2">已同意</a-select-option>
                  <a-select-option value="3">已驳回</a-select-option>
                  <a-select-option value="4">已撤销</a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
          </a-row>
        </template>

        <a-row>
          <a-col :span="12">
            <a-form-model-item label="标题" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="title"
              style="margin-bottom: 10px;">
              <a-input :disabled="disabled" v-model="model.title" placeholder="请输入标题"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12" v-if="pageType === 'add' || pageType === 'edit' || pageType === 'anew' || pageType === 'history' || pageType === 'approver'">
            <a-form-model-item label="申请部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="departName"
              style="margin-bottom: 10px;">
              <a-select :disabled="disabled" placeholder="请选择申请部门" :value="model.departName"
                @change="handleChange('depart',$event)">
                <a-select-option v-for="(item,index) in departList" :key="index" :value="item">
                  {{item.label}}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="12" v-if="(pageType === 'detail') && (receiptsModel === '7' || receiptsModel === '6')">
            <a-form-model-item label="中标价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="biddingPrice"
              style="margin-bottom: 10px;">
              <a-input :disabled="disabled" v-model="model.biddingPrice" placeholder="请输入中标价"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12" v-else-if="(pageType === 'detail') && (receiptsModel === '9' || receiptsModel === '8')">
            <a-form-model-item label="招采单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="biddingNumber"
              style="margin-bottom: 10px;">
              <a-input :disabled="disabled" v-model="model.biddingNumber" placeholder="请输入招采单号"></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="12" v-if="pageType != 'anew'">
            <a-form-model-item label="项目" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectName"
              style="margin-bottom: 10px;">
              <a-select :disabled="disabled" placeholder="请选择项目" :value="model.projectName"
                @change="handleChange('project',$event)">
                <a-select-option v-for="(item,index) in levelOneOptions" :key="index" :value="item">
                  {{item.label}}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="12" v-if="pageType === 'anew'">
            <a-form-model-item label="项目" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectName"
              style="margin-bottom: 10px;">
              <a-select :disabled="true" placeholder="请选择项目" :value="model.projectName"
                @change="handleChange('project',$event)">
                <a-select-option v-for="(item,index) in levelOneOptions" :key="index" :value="item">
                  {{item.label}}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="招采名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name"
              style="margin-bottom: 10px;">
              <a-input :disabled="disabled" v-model="model.name" placeholder="请输入招采名称"></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="12">
            <a-form-model-item :label="(receiptsModel === '7' || receiptsModel === '9')?'物资条数':'分包项目条数'"
              :labelCol="labelCol" :wrapperCol="wrapperCol" prop="number" style="margin-bottom: 10px;">
              <a-input :disabled="disabled" v-model="model.number"
                :placeholder="'请输入' + (receiptsModel === '7' || receiptsModel === '9')?'物资条数':'分包项目条数'"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item :label="(receiptsModel === '8' || receiptsModel === '9')?'发标时间':'招采开始时间'" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="startTime"
              style="margin-bottom: 10px;">
              <a-date-picker :disabled="disabled" :placeholder="(receiptsModel === '8' || receiptsModel === '9')?'请选择发标时间':'请选择招采开始时间'" format="YYYY-MM-DD" v-model="model.startTime"
                style="width:100%;" />
            </a-form-model-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="12">
            <a-form-model-item label="总金额(不含税)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taxExclusiveMoney"
              style="margin-bottom: 10px;">
              <a-input :disabled="disabled" v-model="model.taxExclusiveMoney" placeholder="请输入总金额(不含税)"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item :label="(receiptsModel === '8' || receiptsModel === '9')?'结标时间':'招采结束时间'" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="endTime"
              style="margin-bottom: 10px;">
              <a-date-picker :disabled="disabled" :placeholder="(receiptsModel === '8' || receiptsModel === '9')?'请选择结标时间':'请选择招采结束时间'" format="YYYY-MM-DD" v-model="model.endTime"
                style="width:100%;" />
            </a-form-model-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="12">
            <a-form-model-item label="总金额(含税)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taxInclusiveMoney"
              style="margin-bottom: 10px;">
              <a-input :disabled="disabled" v-model="model.taxInclusiveMoney" placeholder="请输入总金额(含税)"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12" v-if="pageType === 'add' || pageType ===  'edit' || pageType === 'anew' || pageType === 'history' || pageType === 'approver'">
            <a-form-model-item label="中标价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="biddingPrice"
              style="margin-bottom: 10px;">
              <a-input :disabled="disabled" v-model="model.biddingPrice" placeholder="请输入中标价"></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>

        <a-row v-if="((receiptsModel === '8' || receiptsModel === '9') && (pageType === 'add' || pageType === 'edit' || pageType === 'anew' || pageType === 'history' || pageType === 'approver'))">
          <a-col :span="12">
            <a-form-model-item label="招采单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="biddingNumber"
              style="margin-bottom: 10px;">
              <a-input :disabled="disabled" v-model="model.biddingNumber" placeholder="请输入招采单号"></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol2" :wrapperCol="wrapperCol2" prop="remark"
              style="margin-bottom: 10px;margin-left: 0px;">
              <!-- <textarea :disabled="disabled" v-model="model.remark" cols="100" rows="2" style="width: 93%;"
                placeholder="请输入备注"></textarea> -->
              <div style="position: relative;">
                <textarea :disabled="disabled" v-model="model.remark" cols="100" rows="3" style="width: 95%;padding-right: 30px;line-height: 25px;" maxlength="500"
                  placeholder="请输入备注"></textarea>
                  <div style="position: absolute;right: 64px;bottom: 20px;font-size: 12px;">{{model.remark.length}}/500</div>
              </div>
            </a-form-model-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="24">
            <a-form-model-item label="中标候选人" :labelCol="labelCol2" :wrapperCol="wrapperCol2" prop="companyList"
              style="margin-bottom: 10px;margin-left: 0px;font-weight: 600; width: 95%;">
              <div style="display: flex;flex-direction: column;">
                <div style="display: flex;align-items: center;">
                  <a-button type="primary" @click="handleAddCom" icon="plus"
                    style="width: 150px;text-align: center;margin-bottom: 10px;margin-right: 10px;margin-left: 5px;" v-if="pageType === 'add' ||pageType === 'edit' ||pageType === 'anew'">添加中标候选人</a-button>
                  <a-button type="danger" @click="handleDelCom" v-if="(selectedRowKeys && selectedRowKeys.length>0) && (pageType === 'add' ||pageType === 'edit' ||pageType === 'anew')"
                    style="width: 100px;text-align: center;margin-bottom: 10px;">批量删除</a-button>
                </div>

                <a-table :columns="columns" :dataSource="model.companyList" :pagination="false"
                  :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
                  style="margin-bottom: 20px;">
                  <template v-for="(col, i) in ['name', 'relation', 'phone','taxRate','taxInclusiveMoney','money']"
                    :slot="col" slot-scope="text, record, index">
                    <a-input :key="col" v-if="record.editable && (col != 'taxRate')" style="margin: -5px 0" :value="text"
                      :placeholder="columns[i].title" @change="e => handleChange2(e.target.value, record.key, col)" />
                    <a-input-number :key="col" v-else-if="record.editable && (col == 'taxRate')" :min="0" :max="100" :step="0.1" :default-value="text"
                      :formatter="text => `${text}%`" :parser="text => text.replace('%', '')" 
                       :placeholder="columns[i].title" style="margin: -5px 0" 
                      @change="e => handleChange3(e, record.key, col)" />
                    <template v-else>{{ text }}</template>
                  </template>
                  <template slot="operation" slot-scope="text, record, index">
                    <template v-if="record.editable">
                      <span v-if="record.isNew">
                        <a @click="saveRow(record.key)">添加</a>
                        <a-divider type="vertical" />
                        <a-popconfirm title="是否要删除此行？" @confirm="remove(record.key)">
                          <a>删除</a>
                        </a-popconfirm>
                      </span>
                      <span v-else>
                        <a @click="saveRow(record.key)">保存</a>
                        <a-divider type="vertical" />
                        <a @click="cancel(record.key)">取消</a>
                      </span>
                    </template>
                    <span v-else>
                      <a @click="toggle(record.key)">编辑</a>
                      <a-divider type="vertical" />
                      <a-popconfirm title="是否要删除此行？" @confirm="remove(record.key)">
                        <a>删除</a>
                      </a-popconfirm>
                    </span>
                  </template>
                </a-table>

              </div>
            </a-form-model-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="24">
            <a-form-model-item label="附件资料" :labelCol="labelCol2" :wrapperCol="wrapperCol2" prop="attachment"
              style="margin:0 60px 10px 20px">
              <j-upload v-model="model.attachment" :disabled="disabled" :buttonVisible="!disabled"
                style="margin-left: 5px;"></j-upload>
            </a-form-model-item>
          </a-col>
        </a-row>

        <a-row v-if="pageType === 'detail' || pageType === 'approver' || pageType === 'history'">
          <a-form-model-item label="审核流程" :labelCol="labelCol2" :wrapperCol="wrapperCol2" prop="remark"
            style="margin-bottom: 10px;margin-left: 0px;">
            <app-flow :list="list" :pageType="pageType" :approver="approver"></app-flow>
          </a-form-model-item>
        </a-row>
        <a-row v-if="!(pageType === 'approver'?false:true)">
          <a-button style="background: orange;color: white;border:1px solid orange;margin-left: 118px;"
            @click="handleOpen('history')">查看原审核记录</a-button>
        </a-row>

      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>
  import {
    httpAction,
    getAction
  } from '@/api/manage'
  import {
    validateDuplicateValue
  } from '@/utils/util'
  import appFlow from '../components/appFlow.vue'
  export default {
    name: 'WtBrandForm',
    components: {
      appFlow
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: true,
        required: false,
      },
      pageType: {
        type: String,
        default: '', //add-新增 anew-重复提交 edit-编辑 detail-详情 approver-审批
      },
      billsTemplateName:{
        type: String,
        default: '',
      },
      receiptsModel:{
        type: String,
        default: '',
      },
      defaultModel: {
        type: Boolean,
        default () {
          return {

          }
        },
      },
    },
    data() {
      return {
        title: '',
        model: {
          billsTemplateName: '',
          title: '',
          departName: '',
          departId: '',
          projectId: '',
          projectName: '',
          name: '',
          number: '',
          startTime: '',
          endTime: '',
          taxExclusiveMoney: '',
          taxInclusiveMoney: '',
          biddingPrice: '',
          status: '',
          remark: '',
          status: '',
          attachment: '',
          companyList: [],
        },
        labelCol: {
          xs: {
            span: 24
          },
          sm: {
            span: 6
          },
        },
        wrapperCol: {
          xs: {
            span: 24
          },
          sm: {
            span: 16
          },
        },
        labelCol2: {
          xs: {
            span: 24
          },
          sm: {
            span: 3
          },
        },
        wrapperCol2: {
          xs: {
            span: 24
          },
          sm: {
            span: 21
          },
        },
        confirmLoading: false,
        validatorRules: {},
        levelOneOptions: [],
        departList: [], //部门列表
        countersignTemplateId: '',
        list: [],
        url: {
          detail: '/countersign/wtCountersignBidding/queryByCountersignId',
          add: '/countersign/wtCountersignBidding/add',
          edit: '/countersign/wtCountersignBidding/edit',
          anew: '/countersign/wtCountersignBidding/editSubmit',
          approver: '/countersign/wtCountersignProcess/submitExamineApprove',
        },
        columns: [{
            title: '中标候选人名称',
            dataIndex: 'name',
            key: 'name',
            width: '25%',
            scopedSlots: {
              customRender: 'name'
            }
          },
          {
            title: '联系人',
            dataIndex: 'relation',
            key: 'relation',
            width: '15%',
            scopedSlots: {
              customRender: 'relation'
            }
          },
          {
            title: '联系电话',
            dataIndex: 'phone',
            key: 'phone',
            width: '20%',
            scopedSlots: {
              customRender: 'phone'
            }
          },
          {
            title: '税率',
            dataIndex: 'taxRate',
            key: 'taxRate',
            width: '10%',
            scopedSlots: {
              customRender: 'taxRate'
            }
          },
          {
            title: '含税金额',
            dataIndex: 'taxInclusiveMoney',
            key: 'taxInclusiveMoney',
            width: '15%',
            scopedSlots: {
              customRender: 'taxInclusiveMoney'
            }
          },
          {
            title: '不含税金额',
            dataIndex: 'money',
            key: 'money',
            width: '15%',
            scopedSlots: {
              customRender: 'money'
            }
          },
        ],
        approver:'',
        selectedRowKeys: [],
      }
    },
    computed: {
      formDisabled() {
        return this.disabled
      },
    },
    created() {
      if (!!window.localStorage.getItem("pro__Login_Userinfo")) {
        let userInfo = JSON.parse(window.localStorage.getItem("pro__Login_Userinfo")).value;
        this.approver = userInfo.id;
      }
      if (!!window.localStorage.getItem("pro__USER_DEPARTLIST")) {
        let departList = JSON.parse(window.localStorage.getItem("pro__USER_DEPARTLIST")).value;
        if (departList && departList.length > 0) {
          this.departList = departList.map((ite) => ({
            ...ite,
            value: ite.id,
            label: ite.departName
          }))
        }
      }
      //验证表单
      if (this.pageType === 'add' || this.pageType === 'edit' || this.pageType === 'anew') {
        this.validatorRules = {
          title: [{
            required: true,
            message: '标题不能为空,请选择~',
            trigger: 'blur'
          }],
          departName: [{
            required: true,
            message: '申请部门不能为空,请选择~',
            trigger: 'change'
          }],
          projectName: [{
            required: true,
            message: '项目不能为空,请选择~',
            trigger: 'change'
          }],
          name: [{
            required: true,
            message: '招采名称不能为空,请输入~',
            trigger: 'blur'
          }],
          taxExclusiveMoney: [{
            required: true,
            message: '总金额(不含税)不能为空,请输入~',
            trigger: 'blur'
          }],
          taxInclusiveMoney: [{
            required: true,
            message: '总金额(含税)不能为空,请输入~',
            trigger: 'blur'
          }],
          biddingPrice: [{
            required: true,
            message: '中标价不能为空,请输入~',
            trigger: 'blur'
          }],
          companyList: [{
            required: true,
            message: '中标候选人不能为空,请输入~',
            trigger: 'blur'
          }],
          attachment: [{
            required: true,
            message: '附件资料不能为空,请上传~',
            trigger: 'blur'
          }],
        }
        if (this.receiptsModel === '8' || this.receiptsModel === '9') {
          this.validatorRules.biddingNumber = [{
            required: true,
            message: '招采单号不能为空,请输入~',
            trigger: 'blur'
          }]
        }
      };
      if (this.pageType === 'add') {
        this.Dict();
      }
    },
    mounted() {
      if (!!this.defaultModel.id) {
        this.model = JSON.parse(JSON.stringify(this.defaultModel));
        this.list = this.model.list;
        let companyList = this.model.companyList;
        if(companyList && companyList.length>0){
          this.model.companyList = companyList.map(ite=>({
            ...ite,
            key:ite.id,
            editable: false,
            isNew: true
          }))
        }
        
        if (this.levelOneOptions && this.levelOneOptions.length > 0) {
          let info = this.levelOneOptions.find((item) => item.departName == this.model.projectName)
          this.model.projectId = info.id
        }
        if (this.departList && this.departList.length > 0) {
          let info = this.departList.find((item) => item.departName == this.model.departName)
          this.model.departId = info.id
        }
        this.$forceUpdate();
      }
      this.model.billsTemplateName = JSON.parse(JSON.stringify(this.billsTemplateName));
      console.log(12, this.model.billsTemplateName)
    },
    methods: {
      retrieve(record,type){
      	let ret = false;
      	if(record.indexOf(type) != -1){
      		ret = true;
      	}else{
      		ret = false;
      	}
      	return ret
      },
      onSelectChange(selectedRowKeys) {
        console.log('selectedRowKeys changed: ', selectedRowKeys);
        this.selectedRowKeys = selectedRowKeys;
      },
      //表格数据批量删除
      handleDelCom() {
        if (this.selectedRowKeys.length <= 0) {
          this.$message.warning('请选择一条记录！');
          return;
        } else {
          var _self = this;
          this.$confirm({
            title: "确认删除",
            content: "是否删除选中数据?",
            onOk: function() {
              let companyList = JSON.parse(JSON.stringify(_self.model.companyList));
              companyList.forEach((item, index) => {
                _self.$set(item, 'is_sel', false)
                _self.selectedRowKeys.forEach((v, i) => {
                  if (item.key === v) {
                    item.is_sel = true
                  }
                })
              })
              let companyLists = []
              companyList.forEach(ite => {
                if (!ite.is_sel) {
                  companyLists.push(ite)
                }
              })
              _self.selectedRowKeys = [];
              _self.model.companyList = companyLists;
            }
          });
        }
      },
      handleAddCom() {
        let ind = (new Date()).getTime();
        this.model.companyList.push({
          key: ind,
          name: '',
          relation: '',
          phone: '',
          taxRate: '',
          taxInclusiveMoney: '',
          money: '',
          editable: true,
          isNew: true
        });
        console.log(1, this.model.companyList)
        this.$forceUpdate();
      },
      remove(key) {
        const newData = this.model.companyList.filter(item => item.key !== key)
        this.model.companyList = newData
      },
      saveRow(key) {
        let target = this.model.companyList.filter(item => item.key === key)[0]
        target.editable = false
        target.isNew = false
      },
      toggle(key) {
        let target = this.model.companyList.filter(item => item.key === key)[0]
        target.editable = !target.editable
      },
      getRowByKey(key, newData) {
        const data = this.model.companyList
        return (newData || data).filter(item => item.key === key)[0]
      },
      cancel(key) {
        let target = this.model.companyList.filter(item => item.key === key)[0]
        target.editable = false
      },
      handleChange2(value, key, column) {
        const newData = [...this.model.companyList]
        const target = newData.filter(item => key === item.key)[0]
        if (target) {
          target[column] = value
          this.model.companyList = newData
        }
      },
      handleChange3(value, key, column) {
        console.log(23,value, key, column)
        const newData = [...this.model.companyList]
        const target = newData.filter(item => key === item.key)[0]
        if (target) {
          target[column] = value
          this.model.companyList = newData
        }
        console.log(24,this.model.companyList)
      },
      //下拉选择
      handleChange(type, item) {
        console.log(1, type, item);
        if (type === 'project') {
          this.model.projectName = item.label;
          this.model.projectId = item.value;
        } else if (type === 'depart') {
          this.model.departName = item.label;
          this.model.departId = item.value;
        }
      },
      //获取数据字典
      Dict(record) {
        //项目列表
        //getAction(`/sys/sysDepart/getDepartByOrgType?orgType=1`).then((res) => {
        getAction(`/countersign/wtCountersignTemplate/getProjectListBybillsTemplateName?billsTemplateName=${this.billsTemplateName}`).then((res) => {
          if (res.success) {
            let treeList = res.result;
            if (treeList && treeList.length > 0) {
              this.levelOneOptions = [...treeList].map((v) => {
                return {
                  ...v,
                  value: v.id,
                  label: v.departName,
                }
              })
            }
            if (this.pageType === 'edit' || this.pageType === 'anew' || this.pageType === 'detail' || this
              .pageType === 'approver') {
              if (!!record) {
                this.getdata(record);
              }
            }
            this.$forceUpdate();
          }
        })
      },
      //获取数据
      getdata(record) {
        var that = this
        getAction(`/countersign/wtCountersignBidding/queryByCountersignId?countersignId=${record.id}`).then(
          (res) => {
            if (res.success) {
              this.model = res.result;
              this.list = res.result.list;
              if(this.pageType ==='edit' || this.pageType ==='anew'){
                this.model.companyList = res.result.companyList.map(ite=>({
                  ...ite,
                  key:ite.id,
                  editable: true,
                  isNew: true
                }))
              }else{
                this.model.companyList = res.result.companyList.map(ite=>({
                  ...ite,
                  key:ite.id,
                  editable: false,
                  isNew: true
                }))
              }
              if (this.levelOneOptions && this.levelOneOptions.length > 0) {
                let info = this.levelOneOptions.find((item) => item.departName == this.model.projectName)
                this.model.projectId = info.id
              }
              if (this.departList && this.departList.length > 0) {
                let info = this.departList.find((item) => item.departName == this.model.departName)
                console.log(2, info)
                this.model.departId = info.id
              }
              this.$forceUpdate();
            }
          }
        )
      },
      add(record) {
        this.countersignTemplateId = record.id;
        if(!!record.objlist){
          let list = JSON.parse(record.objlist);
          console.log(2,list)
          //let ind = (new Date()).getTime();
          this.model.companyList = list.map((ite,ind)=>({
            name:ite.supplierName,
            relation:ite.relation,
            phone:ite.phone,
            taxRate:ite.supplierPriceItem.taxRate,
            taxInclusiveMoney:ite.supplierPriceItem.taxInclusiveMoney,
            money:ite.supplierPriceItem.money,
            key:ind,
            editable: true,
            isNew: true
          }));
        }
      },
      edit(record) {
        if (this.pageType === 'edit' || this.pageType === 'anew' || this.pageType === 'detail' || this.pageType ===
          'approver') {
          this.Dict(record);
        }
      },
      //查看原审核记录
      handleOpen(type) {
        this.$emit('handleOpen', type);
      },
      submitForm(record) {
        const _self = this
        if (this.pageType === 'add' || this.pageType === 'edit' || this.pageType === 'anew') {
          if (!this.model.projectId) {
            _self.$message.warning('项目不能为空,请选择');
            return;
          }
          if (!this.model.departId) {
            _self.$message.warning('申请部门不能为空,请选择');
            return;
          }
          if (!this.model.name) {
            _self.$message.warning('招采名称不能为空,请输入');
            return;
          }
          if (!this.model.taxExclusiveMoney) {
            _self.$message.warning('总金额（不含税）不能为空,请输入');
            return;
          }
          if (this.receiptsModel === '8' || this.receiptsModel === '9') {
            if (!this.model.biddingNumber) {
              _self.$message.warning('招采单号不能为空,请输入');
              return;
            }
          }
          if (!this.model.taxInclusiveMoney) {
            _self.$message.warning('总金额（含税）不能为空,请输入');
            return;
          }
          if (!this.model.biddingPrice) {
            _self.$message.warning('中标价不能为空,请输入');
            return;
          }
          if (this.model.companyList.length === 0) {
            _self.$message.warning('中标候选人不能为空,请输入');
            return;
          }
          if (!this.model.attachment) {
            _self.$message.warning('附件资料不能为空,请上传');
            return;
          }
        }
        _self.model.billsTemplateName = this.billsTemplateName;
        let params = {};
        let httpurl = ''
        if (_self.pageType === 'add') {
          httpurl = _self.url.add;
          _self.model.countersignTemplateId = this.countersignTemplateId;
          params = _self.model;
        } else if (_self.pageType === 'edit') {
          httpurl = _self.url.edit;
          params = _self.model;
        } else if (_self.pageType === 'anew') {
          httpurl = _self.url.anew;
          params = _self.model;
        } else if (_self.pageType === 'approver') {
          httpurl = _self.url.approver;
          if (this.list && this.list.length > 0) {
            this.list.forEach(ite => {
              if (this.approver === ite.approver && ite.status === '1') {
                params.feedback = ite.feedback;
                params.ideaAttachment = ite.ideaAttachment;
                params.id = ite.id;
              }
            })
          }
          if (!params.feedback) {
            _self.$message.warning('审批意见不能为空,请填写');
            return;
          }
        }
        // 触发表单验证
        _self.confirmLoading = true;
        params.status = record;
        console.log('提交表单', params)
        // debugger
        httpAction(httpurl, params, 'POST')
          .then((res) => {
            if (res.success) {
              _self.$message.success(res.message)
              _self.$emit('ok')
            } else {
              _self.$message.warning(res.message)
            }
          })
          .finally(() => {
            _self.confirmLoading = false
          })
      },
    },
  }
</script>
<style scoped>
  .scroll-view {
    overflow: auto;
    overflow-y: scroll;
  }
</style>